<template>
  <div class="listPing">
    <ul>
      <li v-for="ping of letters" :key="ping" :ref="ping"
          @click="cityPingChage"
          @touchstart="touchstartPing"
          @touchmove="touchmovePing"
          @touchend="touchendPing"
      >
        {{ping}}
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "cityPing",
    props:{
      citys:Object
    },
    data (){
      return {
        touchFT:false
      }
    },
    computed :{
      letters(){
        const letters = []
        for (let i in this.citys){
          letters.push(i)
        }
        return letters
      }
    },
    methods:{
      cityPingChage (e){
        // 第一个是函数名，第二个是变量
        this.$emit('change',e.target.innerText)
      },
      touchstartPing (){
        this.touchFT = true
      },
      touchmovePing (e){
        if(this.touchFT){
          const startY = this.$refs['A'][0].offsetTop
          const touchY = e.touches[0].clientY-79
          const index = Math.floor((touchY - startY)/17)
          if(index>=0 && this.letters.length){
            this.$emit('change',this.letters[index])
          }
        }
      },
      touchendPing (){
        this.touchFT = false
      }
    }
  }
</script>

<style scoped lang="stylus">
  @import "~css/varibles.styl";
  .listPing{ position: absolute;top: 1.58rem;right: 0;bottom: 0;width: 0.3rem;text-align: center;
    display: flex;align-items: center;margin-right: .04rem}
  .listPing li{ width: .3rem;line-height: .34rem;color: #00bcd4;cursor: pointer}
</style>
